﻿using System;
using System.IO;
using Microsoft.Win32;
using PSE.Deployment.Engine;
using PSE.Deployment.Engine.Enums;
using PSE.Deployment.Engine.Interfaces;
using PSE.Deployment.SetupBase;
using PSE.Framework.Cryptography;
using Sinacor.Deployment.Setup.Main;
using Sinacor.Infra.Core.Licensing;

namespace Sinacor.Deployment.Setup.Uninstall.Steps
{
    public class DeleteLicenceFile : BaseStep
    {
        public DeleteLicenceFile(IStepGroup parent)
            : base(parent)
        {
            this.Id = "DeleteLicenceFile";
            this.Description = "Exclusão do arquivo de licença";

            this.ErrorBehavior = StepErrorBehavior.Ignore;
            this.NavigationBehavior = StepNavigationBehavior.NextCancel;

            this.ResetProgress(1);
        }

        public override void Execute()
        {
            this.ResetProgress(1);

            string file = SetupMainFactory.GetInstance<SinacorMain>().Parameter.InstallationPath + @"Sinacor\License\Sinacor.lic";

            this.IncrementProgress(file);

            if (File.Exists(file))
                File.Delete(file);

            if (Directory.Exists(Path.GetDirectoryName(file)))
                PSE.Deployment.Util.File.DeleteEmptyDirectories(SetupMainFactory.GetInstance().Parameter.InstallationPath, Path.GetDirectoryName(file));
        }

        public override void Undo()
        {

        }
    }
}